#include "stdafx.h"
#include "YProactorTokenOnDisconnect.h"
#include "ITcpSession.h"
#include "ITcpSessionCallback.h"
#include <YSimpleSystem/YSimpleSystem.h>

namespace ysimple_network
{
	YProactorTokenOnDisconnect::YProactorTokenOnDisconnect(void)
		: m_pCallback(nullptr)
		, m_pSession(nullptr)
	{
	}


	YProactorTokenOnDisconnect::~YProactorTokenOnDisconnect(void)
	{
	}

	void YProactorTokenOnDisconnect::beginInit( IDisconectCallback& callback, ITCPSession& session )
	{
		resetOverlapped();
		m_pCallback = &callback;
		m_pSession = &session;
		m_pSession->addRef();
	}

	bool YProactorTokenOnDisconnect::onCompleted( bool completionStatus, LONG_PTR completionKey, DWORD dwBytesTransfered )
	{
		m_pCallback->onDisconnected(*m_pSession);
		m_pSession->release();
		return true;
	}

	void YProactorTokenOnDisconnect::endInit( bool success )
	{
		if (success == false)
		{
			m_pSession->release();
		}
	}

}

